// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import FastClick from 'fastclick'
import { WechatPlugin, ToastPlugin, LoadingPlugin } from 'vux'
import VueWechatTitle from 'vue-wechat-title'
import store from './store'
import router from './router'
import filter from './filters'
import common from './common'
import App from './App'

Vue.use(WechatPlugin)
Vue.use(VueWechatTitle)
Vue.use(ToastPlugin)
Vue.use(LoadingPlugin)

FastClick.attach(document.body)

// 引入公共方法
Vue.prototype.common = common

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  store,
  router,
  render: h => h(App)
}).$mount('#app-box')

// 注册全局filters
Object.keys(filter).forEach(k => Vue.filter(k, filter[k]))

// loading
router.beforeEach(function (to, from, next) {
  store.commit('updateLoadingStatus', {
    isLoading: true
  })
  next()
})

router.afterEach(function (to) {
  store.commit('updateLoadingStatus', {
    isLoading: false
  })
})
